new Vue({
    el: '#app',
    data: {
        loginForm: {
            username: '',
            password: ''
        },
        loginRules: {
            username: [{required: true, trigger: 'blur', validator: this.validateUsername}],
            password: [{required: true, trigger: 'blur', validator: this.validatePassword}]
        },
        passwordType: 'password',
        loading: false,
        showDialog: false
    },

    methods: {
        validateUsername: function (rule, value, callback) {
            if (!isvalidUsername(value)) {
                callback(new Error('用户名不能为空'))
            } else {
                callback()
            }
        },
        validatePassword: function (rule, value, callback) {
            if (value.length < 6) {
                callback(new Error('The password can not be less than 6 digits'))
            } else {
                callback()
            }
        },
        showPwd : function() {
            if (this.passwordType === 'password') {
                this.passwordType = ''
            } else {
                this.passwordType = 'password'
            }
        },
        handleLogin: function() {
            var $this = this;
            $.ajax({
                type: "POST",
                url: "/login/login",
                data: {
                    username: this.loginForm.username,
                    password: this.loginForm.password
                },
                dataType: "json",
                success: function(r){
                    if(r.code == 0){//登录成功
                        localStorage.setItem("refreshToken", r.data.refreshToken);
                        localStorage.setItem("token", r.data.token);
                        location.href ='index.html';
                    }else{
                        $this.$message(r.msg);
                    }
                }
            });
        }
    },
    created() {
        // window.addEventListener('hashchange', this.afterQRScan)
    },
    destroyed() {
        // window.removeEventListener('hashchange', this.afterQRScan)
    }
});